﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotNet.Schema;

namespace ConsoleApplication1.YIBIYIMVC
{
    public partial class Map
    {
        public string NameSpacePR;
        public TableInfo DBTable;

        public Map(TableInfo t, string ns)
        {
            if (t == null)
                throw new Exception("参数t，不能为null。");

            this.NameSpacePR = ns;
            this.DBTable = t;
        }

        public string BuildPropertieStr(ColumnInfo column)
        {
            if (!column.HasStringLength && column.Nullable)
                return string.Empty;

            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("this.Property(t => t.{0})", column.PascalName);
            if (column.HasStringLength)
            {
                sb.Append("\r\n                ");
                sb.AppendFormat(".HasMaxLength({0})", column.MaxLength);
            }
            if (!column.Nullable)
            {
                sb.Append("\r\n                ");
                sb.Append(".IsRequired()");
            }
            sb.Append(";");
            return sb.ToString();
        }
    }
}
